package cn.com.stary1993.kite.captcha.support.behavior;

import cloud.tianai.captcha.common.response.ApiResponse;
import cloud.tianai.captcha.generator.ImageCaptchaGenerator;
import cloud.tianai.captcha.generator.common.model.dto.GenerateParam;
import cloud.tianai.captcha.resource.ImageCaptchaResourceManager;
import cloud.tianai.captcha.validator.ImageCaptchaValidator;
import cloud.tianai.captcha.validator.common.model.dto.ImageCaptchaTrack;
import cn.com.stary1993.kite.captcha.support.Captcha;
import cn.com.stary1993.kite.captcha.vo.BehaviorCaptchaVO;
import cn.com.stary1993.kite.captcha.vo.CaptchaResponse;
import cn.com.stary1993.kite.captcha.vo.CaptchaVO;

/**
 * 行为验证码应用程序
 *
 * @author stary1993
 */
public abstract class BehaviorImageCaptcha implements Captcha {

    @Override
    public abstract CaptchaResponse<? extends CaptchaVO> generate();

    /**
     * 生成滑块验证码
     *
     * @param type type类型
     * @return CaptchaResponse<SliderCaptchaVO>
     */
    public abstract CaptchaResponse<BehaviorCaptchaVO> generate(String type);

    /**
     * 生成滑块验证码
     *
     * @param type      type类型
     * @param obfuscate 是否混淆
     * @return CaptchaResponse<SliderCaptchaVO>
     */
    public abstract CaptchaResponse<BehaviorCaptchaVO> generate(String type, boolean obfuscate);

    /**
     * 生成验证码
     *
     * @param type             type
     * @param obfuscate        obfuscate
     * @param captchaImageType CaptchaImageType
     * @return CaptchaResponse<ImageCaptchaVO>
     */
    public abstract CaptchaResponse<BehaviorCaptchaVO> generate(String type,
                                                                boolean obfuscate,
                                                                BehaviorImageCaptchaFormat captchaImageType);

    /**
     * 生成滑块验证码
     *
     * @param param param
     * @return CaptchaResponse<SliderCaptchaVO>
     */
    public abstract CaptchaResponse<BehaviorCaptchaVO> generate(GenerateParam param);

    /**
     * 匹配
     *
     * @param id                验证码的ID
     * @param imageCaptchaTrack 滑动轨迹
     * @return 匹配成功返回true， 否则返回false
     */
    public abstract ApiResponse<?> matching(String id, ImageCaptchaTrack imageCaptchaTrack);

    /**
     * 兼容一下旧版本，新版本建议使用 {@link BehaviorImageCaptcha#matching(String, ImageCaptchaTrack)}
     *
     * @param id         id
     * @param percentage 百分比数据
     * @return boolean
     */
    @Deprecated
    public abstract boolean matching(String id, Float percentage);

    /**
     * 获取验证码资源管理器
     *
     * @return SliderCaptchaResourceManager
     */
    public abstract ImageCaptchaResourceManager getImageCaptchaResourceManager();

    /**
     * 获取验证码验证器
     *
     * @return SliderCaptchaValidator
     */
    public abstract ImageCaptchaValidator getImageCaptchaValidator();

    /**
     * 设置 SliderCaptchaValidator 验证码验证器
     *
     * @param imageCaptchaValidator imageCaptchaValidator
     */
    public abstract void setImageCaptchaValidator(ImageCaptchaValidator imageCaptchaValidator);

    /**
     * 获取验证码生成器
     *
     * @return SliderCaptchaTemplate
     */
    public abstract ImageCaptchaGenerator getImageCaptchaTemplate();

    /**
     * 设置 ImageCaptchaGenerator 验证码生成器
     *
     * @param imageCaptchaGenerator SliderCaptchaGenerator
     */
    public abstract void setImageCaptchaTemplate(ImageCaptchaGenerator imageCaptchaGenerator);

}
